#!/bin/bash

if [ -n "$2" ]
then
	do_date=$2
else
	#echo 必须给我传一个日期
	#exit
	do_date= $(date -d yesterday +%F) 
fi

echo 当前要操作的日期是$do_date


dws_user_user_login_td="
insert overwrite table dws_user_user_login_td partition (dt='$do_date')
select
       user_id,
       max(login_date_last),
       sum(login_count_td)
from (
        --查询历史至前天的历史汇总
         select user_id,
                login_date_last,
                login_count_td
         from dws_user_user_login_td
         where dt = date_sub('$do_date',1)
         union all
        --查询昨天的登录数据
         select user_id,
                dt,
                count(user_id)
         from dwd_user_login_inc
         where dt = '$do_date'
         group by user_id,dt
     )t
group by user_id;
"

case $1 in
"dws_user_user_login_td")
	hive --database edu -e "$dws_user_user_login_td"
	;;
"all")
	hive --database edu -e "$dws_user_user_login_td"
	;;
esac